package m1_simple;


import com.rabbitmq.client.*;

import java.io.IOException;

public class Consumer {
    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.64.140");
        factory.setPort(5672);
        factory.setUsername("admin");
        factory.setPassword("admin");
        Connection con=factory.newConnection();
        Channel c = con.createChannel();
        c.queueDeclare("helloworld",false,false,false,null);
        DeliverCallback deliverCallback = new DeliverCallback(){
            @Override
            public void handle(String s, Delivery delivery) throws IOException {
                byte[] a=delivery.getBody();
                String msg=new String(a);
                System.out.println("收到："+msg);
            }
        };
        CancelCallback cancelCallback = new CancelCallback(){
            @Override
            public void handle(String s) throws IOException {

            }
        };

        c.basicConsume("helloworld",true,deliverCallback,cancelCallback);
    }

}
